package com.ruoyi.web.controller.hospital;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.hospital.*;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.*;
import com.ruoyi.hospital.service.IMrInLabService;
import com.ruoyi.hospital.service.IMrOutDataService;
import com.ruoyi.system.service.LsYySqlServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.bind.JAXBException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/hospital/MrOut")
public class MrOutController extends BaseController {

    @Autowired
    IMrOutDataService mrOutDataService;
    @Autowired
    IMrInLabService mrInLabService;
    @Autowired
    LsYySqlServerService lsYySqlServerService;

    @GetMapping("/list")
    public TableDataInfo list(OutPatList outPatList) {
//        actPatList.setPageNum((actPatList.getPageNum() - 1) * actPatList.getPageSize());
//        System.out.println(actPatList.getPageNum());
//        System.out.println(actPatList.getPageSize());
        List<OutPatList> list = mrOutDataService.getOutPatList(outPatList);
        Integer total = mrOutDataService.getOutPatListCount(outPatList);
        return getDataTable(list,total);
    }

    @GetMapping("/add")
    public AjaxResult add(OutPatList outPatList) {
        String id = outPatList.getPatientId() + '-' + outPatList.getOutTimes();
        System.out.println(id);
        outPatList.setId(id);
        mrOutDataService.deletedOutPatList(outPatList.getId());
        mrOutDataService.addOutPatList(outPatList);
        return success(outPatList);
    }

    @GetMapping("/updateOutPatList")
    public AjaxResult updateOutPatList(OutPatList outPatList) {
        String id = outPatList.getPatientId() + '-' + outPatList.getOutTimes();
        System.out.println(id);
        outPatList.setId(id);
        mrOutDataService.updateOutPatList(outPatList);
        return success("更新成功");
    }


    @GetMapping( "/MrOutData")
    public AjaxResult getMrOutData(OutPatList outPatList) throws JAXBException {
//        System.out.println("patientId"+actPatList.getPatientId());
//        System.out.println("times"+actPatList.getInNums());
//        String mrOutData = lsYySqlServerService.getMrOutData(outPatList.getPatientId(),Integer.parseInt(outPatList.getOutTimes()));
//        String mrInLab = lsYySqlServerService.getMrInLab(outPatList.getPatientId(),Integer.parseInt(outPatList.getOutTimes()));
//        String mrInspection = lsYySqlServerService.getMrInspection(outPatList.getPatientId(),Integer.parseInt(outPatList.getOutTimes()));
//        System.out.println("mrIndata"+mrIndata);
//        System.out.println("mrInLab"+mrInLab);
//        System.out.println("mrInspection"+mrInspection);
        String mrOutData = "<mrOutData>\n" +
                "  <mrOutBaisc>\n" +
                "    <medicalClass>1</medicalClass>\n" +
                "    <mdtrtsn>000338082200-3</mdtrtsn>\n" +
                "    <onlyId>000338082200-3</onlyId>\n" +
                "    <organizationId>49455020-4</organizationId>\n" +
                "    <organization>日照市岚山区人民医院</organization>\n" +
                "    <mrId>412921196805301510</mrId>\n" +
                "    <idCard>412921196805301510</idCard>\n" +
                "    <name>宁军</name>\n" +
                "    <medicalPayment />\n" +
                "    <healthCard />\n" +
                "    <passport />\n" +
                "    <sex>1</sex>\n" +
                "    <birthday>1968/05/30</birthday>\n" +
                "    <ageYear>56</ageYear>\n" +
                "    <ageMonth />\n" +
                "    <ageDay />\n" +
                "    <nationality>CHN</nationality>\n" +
                "    <nativePlace />\n" +
                "    <nation>01</nation>\n" +
                "    <address>山东省日照市岚山区万斛路13号竹云山庄小区29号楼1单元302室</address>\n" +
                "    <addrTelephone>15898985322</addrTelephone>\n" +
                "    <mobilePhone>15898985322</mobilePhone>\n" +
                "    <eMail />\n" +
                "    <register />\n" +
                "    <registerPlace />\n" +
                "    <registerPostcode />\n" +
                "    <workUnit />\n" +
                "    <unitTelephone />\n" +
                "    <unitPostcode />\n" +
                "    <linkmanCard />\n" +
                "    <linkmanAddr />\n" +
                "    <linkmanTele>15898985322</linkmanTele>\n" +
                "    <inTime>2024-10-14T09:29:23</inTime>\n" +
                "    <inDepaId>1010305</inDepaId>\n" +
                "    <inDepa>普外二科门诊</inDepa>\n" +
                "    <standardSubject>04.01</standardSubject>\n" +
                "    <abo />\n" +
                "    <rh />\n" +
                "    <outWay />\n" +
                "  </mrOutBaisc>\n" +
                "  <mrInDiagnosss>\n" +
                "    <MrOutDiagnoss>\n" +
                "      <diagOrder>6076221</diagOrder>\n" +
                "      <diagTime>2024-10-14T09:33:49.400</diagTime>\n" +
                "      <diagType>04</diagType>\n" +
                "      <diagCode>R10.402</diagCode>\n" +
                "      <diagnoss>腹痛</diagnoss>\n" +
                "      <status />\n" +
                "      <treatmentResults />\n" +
                "      <diagTreatment />\n" +
                "    </MrOutDiagnoss>\n" +
                "  </mrInDiagnosss>\n" +
                "  <mrOutRecord>\n" +
                "    <depaId>1010305</depaId>\n" +
                "    <depaName>普外二科门诊</depaName>\n" +
                "    <inTime>2024-10-14T09:29:23</inTime>\n" +
                "    <representor>宁军</representor>\n" +
                "    <relationship />\n" +
                "    <telephone>15898985322</telephone>\n" +
                "    <address>山东省日照市岚山区万斛路13号竹云山庄小区29号楼1单元302室</address>\n" +
                "    <reliability />\n" +
                "    <personalHistory />\n" +
                "    <familyHistory />\n" +
                "  </mrOutRecord>\n" +
                "  <mrOutOrders>\n" +
                "    <MrOutOrder>\n" +
                "      <orderNo>000338082200-3-2</orderNo>\n" +
                "      <orderName>普通门诊诊查费</orderName>\n" +
                "      <orderDepa>普外二科门诊</orderDepa>\n" +
                "      <orderDoctor>代学峰</orderDoctor>\n" +
                "      <orderTime>2024-10-14 09:29:26</orderTime>\n" +
                "      <implementDepa />\n" +
                "      <executor />\n" +
                "      <checked />\n" +
                "      <orderGrouping>0</orderGrouping>\n" +
                "      <orderType>4</orderType>\n" +
                "      <orderClassification />\n" +
                "      <orderCode>1</orderCode>\n" +
                "      <drugType />\n" +
                "      <drugDosageform />\n" +
                "      <drugSpecifications>次</drugSpecifications>\n" +
                "      <drugNumber>1.00</drugNumber>\n" +
                "      <drugFrequency />\n" +
                "      <drugDosage>0.00</drugDosage>\n" +
                "      <drugUseUnit />\n" +
                "      <drugDay>1</drugDay>\n" +
                "      <executionTime />\n" +
                "      <startTime />\n" +
                "      <stopTime />\n" +
                "      <skinTest />\n" +
                "      <cancelTime />\n" +
                "      <stopDoctor />\n" +
                "    </MrOutOrder>\n" +
                "    <MrOutOrder>\n" +
                "      <orderNo>000338082200-3-3</orderNo>\n" +
                "      <orderName>专家门诊诊查费（副主任医师）</orderName>\n" +
                "      <orderDepa>普外二科门诊</orderDepa>\n" +
                "      <orderDoctor>代学峰</orderDoctor>\n" +
                "      <orderTime>2024-10-14 09:29:35</orderTime>\n" +
                "      <implementDepa />\n" +
                "      <executor />\n" +
                "      <checked />\n" +
                "      <orderGrouping>0</orderGrouping>\n" +
                "      <orderType>4</orderType>\n" +
                "      <orderClassification />\n" +
                "      <orderCode>1</orderCode>\n" +
                "      <drugType />\n" +
                "      <drugDosageform />\n" +
                "      <drugSpecifications>次</drugSpecifications>\n" +
                "      <drugNumber>1.00</drugNumber>\n" +
                "      <drugFrequency />\n" +
                "      <drugDosage>0.00</drugDosage>\n" +
                "      <drugUseUnit />\n" +
                "      <drugDay>1</drugDay>\n" +
                "      <executionTime />\n" +
                "      <startTime />\n" +
                "      <stopTime />\n" +
                "      <skinTest />\n" +
                "      <cancelTime />\n" +
                "      <stopDoctor />\n" +
                "    </MrOutOrder>\n" +
                "    <MrOutOrder>\n" +
                "      <orderNo>000338082200-3-4</orderNo>\n" +
                "      <orderName>彩色多普勒超声常规检查（胃肠道）</orderName>\n" +
                "      <orderDepa>普外二科门诊</orderDepa>\n" +
                "      <orderDoctor>代学峰</orderDoctor>\n" +
                "      <orderTime>2024-10-14 09:34:23</orderTime>\n" +
                "      <implementDepa />\n" +
                "      <executor />\n" +
                "      <checked />\n" +
                "      <orderGrouping>0</orderGrouping>\n" +
                "      <orderType>4</orderType>\n" +
                "      <orderClassification />\n" +
                "      <orderCode>1</orderCode>\n" +
                "      <drugType />\n" +
                "      <drugDosageform />\n" +
                "      <drugSpecifications>每个部位</drugSpecifications>\n" +
                "      <drugNumber>1.00</drugNumber>\n" +
                "      <drugFrequency />\n" +
                "      <drugDosage>0.00</drugDosage>\n" +
                "      <drugUseUnit />\n" +
                "      <drugDay>1</drugDay>\n" +
                "      <executionTime />\n" +
                "      <startTime />\n" +
                "      <stopTime />\n" +
                "      <skinTest />\n" +
                "      <cancelTime />\n" +
                "      <stopDoctor />\n" +
                "    </MrOutOrder>\n" +
                "    <MrOutOrder>\n" +
                "      <orderNo>000338082200-3-4</orderNo>\n" +
                "      <orderName>超声计算机图文报告</orderName>\n" +
                "      <orderDepa>普外二科门诊</orderDepa>\n" +
                "      <orderDoctor>代学峰</orderDoctor>\n" +
                "      <orderTime>2024-10-14 09:34:23</orderTime>\n" +
                "      <implementDepa />\n" +
                "      <executor />\n" +
                "      <checked />\n" +
                "      <orderGrouping>0</orderGrouping>\n" +
                "      <orderType>4</orderType>\n" +
                "      <orderClassification />\n" +
                "      <orderCode>2</orderCode>\n" +
                "      <drugType />\n" +
                "      <drugDosageform />\n" +
                "      <drugSpecifications>次</drugSpecifications>\n" +
                "      <drugNumber>1.00</drugNumber>\n" +
                "      <drugFrequency />\n" +
                "      <drugDosage>0.00</drugDosage>\n" +
                "      <drugUseUnit />\n" +
                "      <drugDay>1</drugDay>\n" +
                "      <executionTime />\n" +
                "      <startTime />\n" +
                "      <stopTime />\n" +
                "      <skinTest />\n" +
                "      <cancelTime />\n" +
                "      <stopDoctor />\n" +
                "    </MrOutOrder>\n" +
                "    <MrOutOrder>\n" +
                "      <orderNo>000338082200-3-4</orderNo>\n" +
                "      <orderName>医用消毒超声耦合剂20g</orderName>\n" +
                "      <orderDepa>普外二科门诊</orderDepa>\n" +
                "      <orderDoctor>代学峰</orderDoctor>\n" +
                "      <orderTime>2024-10-14 09:34:23</orderTime>\n" +
                "      <implementDepa />\n" +
                "      <executor />\n" +
                "      <checked />\n" +
                "      <orderGrouping>0</orderGrouping>\n" +
                "      <orderType>4</orderType>\n" +
                "      <orderClassification />\n" +
                "      <orderCode>3</orderCode>\n" +
                "      <drugType />\n" +
                "      <drugDosageform />\n" +
                "      <drugSpecifications>支</drugSpecifications>\n" +
                "      <drugNumber>1.00</drugNumber>\n" +
                "      <drugFrequency />\n" +
                "      <drugDosage>0.00</drugDosage>\n" +
                "      <drugUseUnit />\n" +
                "      <drugDay>1</drugDay>\n" +
                "      <executionTime />\n" +
                "      <startTime />\n" +
                "      <stopTime />\n" +
                "      <skinTest />\n" +
                "      <cancelTime />\n" +
                "      <stopDoctor />\n" +
                "    </MrOutOrder>\n" +
                "    <MrOutOrder>\n" +
                "      <orderNo>000338082200-3-5</orderNo>\n" +
                "      <orderName>血细胞分析（五分类）</orderName>\n" +
                "      <orderDepa>普外二科门诊</orderDepa>\n" +
                "      <orderDoctor>代学峰</orderDoctor>\n" +
                "      <orderTime>2024-10-14 09:34:36</orderTime>\n" +
                "      <implementDepa />\n" +
                "      <executor />\n" +
                "      <checked />\n" +
                "      <orderGrouping>0</orderGrouping>\n" +
                "      <orderType>4</orderType>\n" +
                "      <orderClassification />\n" +
                "      <orderCode>1</orderCode>\n" +
                "      <drugType />\n" +
                "      <drugDosageform />\n" +
                "      <drugSpecifications>项</drugSpecifications>\n" +
                "      <drugNumber>1.00</drugNumber>\n" +
                "      <drugFrequency />\n" +
                "      <drugDosage>0.00</drugDosage>\n" +
                "      <drugUseUnit />\n" +
                "      <drugDay>1</drugDay>\n" +
                "      <executionTime />\n" +
                "      <startTime />\n" +
                "      <stopTime />\n" +
                "      <skinTest />\n" +
                "      <cancelTime />\n" +
                "      <stopDoctor />\n" +
                "    </MrOutOrder>\n" +
                "    <MrOutOrder>\n" +
                "      <orderNo>000338082200-3-5</orderNo>\n" +
                "      <orderName>静脉注射（静脉采血检验)</orderName>\n" +
                "      <orderDepa>普外二科门诊</orderDepa>\n" +
                "      <orderDoctor>代学峰</orderDoctor>\n" +
                "      <orderTime>2024-10-14 09:34:36</orderTime>\n" +
                "      <implementDepa />\n" +
                "      <executor />\n" +
                "      <checked />\n" +
                "      <orderGrouping>0</orderGrouping>\n" +
                "      <orderType>4</orderType>\n" +
                "      <orderClassification />\n" +
                "      <orderCode>3</orderCode>\n" +
                "      <drugType />\n" +
                "      <drugDosageform />\n" +
                "      <drugSpecifications>次</drugSpecifications>\n" +
                "      <drugNumber>1.00</drugNumber>\n" +
                "      <drugFrequency />\n" +
                "      <drugDosage>0.00</drugDosage>\n" +
                "      <drugUseUnit />\n" +
                "      <drugDay>1</drugDay>\n" +
                "      <executionTime />\n" +
                "      <startTime />\n" +
                "      <stopTime />\n" +
                "      <skinTest />\n" +
                "      <cancelTime />\n" +
                "      <stopDoctor />\n" +
                "    </MrOutOrder>\n" +
                "    <MrOutOrder>\n" +
                "      <orderNo>000338082200-3-5</orderNo>\n" +
                "      <orderName>一次性使用真空采血管（2ml紫色）</orderName>\n" +
                "      <orderDepa>普外二科门诊</orderDepa>\n" +
                "      <orderDoctor>代学峰</orderDoctor>\n" +
                "      <orderTime>2024-10-14 09:34:36</orderTime>\n" +
                "      <implementDepa />\n" +
                "      <executor />\n" +
                "      <checked />\n" +
                "      <orderGrouping>0</orderGrouping>\n" +
                "      <orderType>4</orderType>\n" +
                "      <orderClassification />\n" +
                "      <orderCode>4</orderCode>\n" +
                "      <drugType />\n" +
                "      <drugDosageform />\n" +
                "      <drugSpecifications>支</drugSpecifications>\n" +
                "      <drugNumber>1.00</drugNumber>\n" +
                "      <drugFrequency />\n" +
                "      <drugDosage>0.00</drugDosage>\n" +
                "      <drugUseUnit />\n" +
                "      <drugDay>1</drugDay>\n" +
                "      <executionTime />\n" +
                "      <startTime />\n" +
                "      <stopTime />\n" +
                "      <skinTest />\n" +
                "      <cancelTime />\n" +
                "      <stopDoctor />\n" +
                "    </MrOutOrder>\n" +
                "  </mrOutOrders>\n" +
                "  <mrOutPhysicalsigns>\n" +
                "    <MrOutPhysicalsign>\n" +
                "      <depaId>1010305</depaId>\n" +
                "      <inTime>2024-10-14T09:29:23</inTime>\n" +
                "      <tNo />\n" +
                "      <tNoDay />\n" +
                "      <tNoTime />\n" +
                "      <tTime />\n" +
                "      <infusion />\n" +
                "      <upd />\n" +
                "      <sputum />\n" +
                "      <vomiting />\n" +
                "      <drainage />\n" +
                "      <other />\n" +
                "      <ejection />\n" +
                "      <encopresis />\n" +
                "      <shitNumber />\n" +
                "      <catheterization />\n" +
                "      <sickbed />\n" +
                "      <weight />\n" +
                "      <height />\n" +
                "      <ac />\n" +
                "      <sbp />\n" +
                "      <dbp />\n" +
                "      <pulseDeficit />\n" +
                "      <pulserate />\n" +
                "      <usingPump />\n" +
                "      <respiratoryRate />\n" +
                "      <usingRespirators />\n" +
                "      <temperature />\n" +
                "      <physicalCooling />\n" +
                "      <pcTemperature />\n" +
                "      <oxygenSaturation />\n" +
                "      <nurse />\n" +
                "      <nurseId />\n" +
                "    </MrOutPhysicalsign>\n" +
                "  </mrOutPhysicalsigns>\n" +
                "</mrOutData>";
        String mrInLab = "<mrInLabsData>\n" +
                "  <mrInLabs>\n" +
                "    <MrInLab>\n" +
                "      <medicalClass>3</medicalClass>\n" +
                "      <mdtrtsn>000347449800-1</mdtrtsn>\n" +
                "      <onlyId>000347449800-1</onlyId>\n" +
                "      <organizationId>49455020-4</organizationId>\n" +
                "      <organization>日照市岚山区人民医院</organization>\n" +
                "      <mrId>376019</mrId>\n" +
                "      <orderNo>0</orderNo>\n" +
                "      <reportNo>4657090</reportNo>\n" +
                "      <inspectTime>2024-08-22 09:19:37</inspectTime>\n" +
                "      <inspectCode>0403443</inspectCode>\n" +
                "      <inspectName>*梅毒螺旋体抗体</inspectName>\n" +
                "      <inspectResult>0.03</inspectResult>\n" +
                "      <measurementUnit>S/CO</measurementUnit>\n" +
                "      <referenceToplimit>1.0000</referenceToplimit>\n" +
                "      <referenceLowerlimit>0.0000</referenceLowerlimit>\n" +
                "      <referenceValue>0~1</referenceValue>\n" +
                "      <inspectMethod />\n" +
                "      <inspectUnit>日照市岚山区人民医院</inspectUnit>\n" +
                "      <inspectDepa>检验科</inspectDepa>\n" +
                "      <rapporteur>陈丽冰</rapporteur>\n" +
                "      <checked>陈庆云</checked>\n" +
                "    </MrInLab>\n" +
                "    <MrInLab>\n" +
                "      <medicalClass>3</medicalClass>\n" +
                "      <mdtrtsn>000347449800-1</mdtrtsn>\n" +
                "      <onlyId>000347449800-1</onlyId>\n" +
                "      <organizationId>49455020-4</organizationId>\n" +
                "      <organization>日照市岚山区人民医院</organization>\n" +
                "      <mrId>376019</mrId>\n" +
                "      <orderNo>0</orderNo>\n" +
                "      <reportNo>4656704</reportNo>\n" +
                "      <inspectTime>2024-08-22 08:07:21</inspectTime>\n" +
                "      <inspectCode>0101030</inspectCode>\n" +
                "      <inspectName>平均血小板体积[MPV]</inspectName>\n" +
                "      <inspectResult>9.90</inspectResult>\n" +
                "      <measurementUnit>fL</measurementUnit>\n" +
                "      <referenceToplimit>13.5000</referenceToplimit>\n" +
                "      <referenceLowerlimit>6.8000</referenceLowerlimit>\n" +
                "      <referenceValue>6.8~13.5</referenceValue>\n" +
                "      <inspectMethod />\n" +
                "      <inspectUnit>日照市岚山区人民医院</inspectUnit>\n" +
                "      <inspectDepa>检验科</inspectDepa>\n" +
                "      <rapporteur>张薇薇</rapporteur>\n" +
                "      <checked>杨晓东</checked>\n" +
                "    </MrInLab>\n" +
                "    <MrInLab>\n" +
                "      <medicalClass>3</medicalClass>\n" +
                "      <mdtrtsn>000347449800-1</mdtrtsn>\n" +
                "      <onlyId>000347449800-1</onlyId>\n" +
                "      <organizationId>49455020-4</organizationId>\n" +
                "      <organization>日照市岚山区人民医院</organization>\n" +
                "      <mrId>376019</mrId>\n" +
                "      <orderNo>0</orderNo>\n" +
                "      <reportNo>4656876</reportNo>\n" +
                "      <inspectTime>2024-08-22 09:02:32</inspectTime>\n" +
                "      <inspectCode>0301014</inspectCode>\n" +
                "      <inspectName>*谷草转氨酶[AST]</inspectName>\n" +
                "      <inspectResult>31.20</inspectResult>\n" +
                "      <measurementUnit>U/L</measurementUnit>\n" +
                "      <referenceToplimit>37.0000</referenceToplimit>\n" +
                "      <referenceLowerlimit>无</referenceLowerlimit>\n" +
                "      <referenceValue>≤32</referenceValue>\n" +
                "      <inspectMethod />\n" +
                "      <inspectUnit>日照市岚山区人民医院</inspectUnit>\n" +
                "      <inspectDepa>检验科</inspectDepa>\n" +
                "      <rapporteur>杨晓东</rapporteur>\n" +
                "      <checked>张海英</checked>\n" +
                "    </MrInLab>\n" +
                "    <MrInLab>\n" +
                "      <medicalClass>3</medicalClass>\n" +
                "      <mdtrtsn>000347449800-1</mdtrtsn>\n" +
                "      <onlyId>000347449800-1</onlyId>\n" +
                "      <organizationId>49455020-4</organizationId>\n" +
                "      <organization>日照市岚山区人民医院</organization>\n" +
                "      <mrId>376019</mrId>\n" +
                "      <orderNo>0</orderNo>\n" +
                "      <reportNo>4656704</reportNo>\n" +
                "      <inspectTime>2024-08-22 08:07:21</inspectTime>\n" +
                "      <inspectCode>0101012</inspectCode>\n" +
                "      <inspectName>嗜碱性粒细胞计数[BAS#]</inspectName>\n" +
                "      <inspectResult>0.00</inspectResult>\n" +
                "      <measurementUnit>10^9/L</measurementUnit>\n" +
                "      <referenceToplimit>0.2000</referenceToplimit>\n" +
                "      <referenceLowerlimit>0.0000</referenceLowerlimit>\n" +
                "      <referenceValue>0~0.2</referenceValue>\n" +
                "      <inspectMethod />\n" +
                "      <inspectUnit>日照市岚山区人民医院</inspectUnit>\n" +
                "      <inspectDepa>检验科</inspectDepa>\n" +
                "      <rapporteur>张薇薇</rapporteur>\n" +
                "      <checked>杨晓东</checked>\n" +
                "    </MrInLab>\n" +
                "    <MrInLab>\n" +
                "      <medicalClass>3</medicalClass>\n" +
                "      <mdtrtsn>000347449800-1</mdtrtsn>\n" +
                "      <onlyId>000347449800-1</onlyId>\n" +
                "      <organizationId>49455020-4</organizationId>\n" +
                "      <organization>日照市岚山区人民医院</organization>\n" +
                "      <mrId>376019</mrId>\n" +
                "      <orderNo>0</orderNo>\n" +
                "      <reportNo>4656876</reportNo>\n" +
                "      <inspectTime>2024-08-22 09:02:32</inspectTime>\n" +
                "      <inspectCode>0301021</inspectCode>\n" +
                "      <inspectName>*总胆固醇[CHO]</inspectName>\n" +
                "      <inspectResult>3.88</inspectResult>\n" +
                "      <measurementUnit>mmol/L</measurementUnit>\n" +
                "      <referenceToplimit>5.2000</referenceToplimit>\n" +
                "      <referenceLowerlimit>无</referenceLowerlimit>\n" +
                "      <referenceValue>≤5.2</referenceValue>\n" +
                "      <inspectMethod />\n" +
                "      <inspectUnit>日照市岚山区人民医院</inspectUnit>\n" +
                "      <inspectDepa>检验科</inspectDepa>\n" +
                "      <rapporteur>杨晓东</rapporteur>\n" +
                "      <checked>张海英</checked>\n" +
                "    </MrInLab>\n" +
                "    <MrInLab>\n" +
                "      <medicalClass>3</medicalClass>\n" +
                "      <mdtrtsn>000347449800-1</mdtrtsn>\n" +
                "      <onlyId>000347449800-1</onlyId>\n" +
                "      <organizationId>49455020-4</organizationId>\n" +
                "      <organization>日照市岚山区人民医院</organization>\n" +
                "      <mrId>376019</mrId>\n" +
                "      <orderNo>0</orderNo>\n" +
                "      <reportNo>4656876</reportNo>\n" +
                "      <inspectTime>2024-08-22 09:02:32</inspectTime>\n" +
                "      <inspectCode>0301028</inspectCode>\n" +
                "      <inspectName>*尿素[UREA]</inspectName>\n" +
                "      <inspectResult>2.90</inspectResult>\n" +
                "      <measurementUnit>mmol/L</measurementUnit>\n" +
                "      <referenceToplimit>8.3000</referenceToplimit>\n" +
                "      <referenceLowerlimit>1.7000</referenceLowerlimit>\n" +
                "      <referenceValue>2.76~8.07</referenceValue>\n" +
                "      <inspectMethod />\n" +
                "      <inspectUnit>日照市岚山区人民医院</inspectUnit>\n" +
                "      <inspectDepa>检验科</inspectDepa>\n" +
                "      <rapporteur>杨晓东</rapporteur>\n" +
                "      <checked>张海英</checked>\n" +
                "    </MrInLab>\n" +
                "  </mrInLabs>\n" +
                "</mrInLabsData>";


        String mrInspection = "<mrInspectionsData>\n" +
                "  <mrInInspections>\n" +
                "    <MrInInspection>\n" +
                "      <medicalClass>3</medicalClass>\n" +
                "      <mdtrtsn>000347449800-1</mdtrtsn>\n" +
                "      <onlyId>000347449800-1</onlyId>\n" +
                "      <organizationId>49455020-4</organizationId>\n" +
                "      <organization>日照市岚山区人民医院</organization>\n" +
                "      <mrId>376019</mrId>\n" +
                "      <orderNo>0</orderNo>\n" +
                "      <reportNo>3552741</reportNo>\n" +
                "      <classification>01</classification>\n" +
                "      <inspectTime>2024-08-22 14:23:51</inspectTime>\n" +
                "      <inspectObjective>CT</inspectObjective>\n" +
                "      <inspectCode>002374;002411;002490;002514</inspectCode>\n" +
                "      <inspectName>颅脑CT平扫（64排）;骨盆CT平扫(64排);左侧尺桡骨CT平扫+三维重建（64排）;胸部、上腹部CT平扫+肋骨重建</inspectName>\n" +
                "      <inspectPosition>左尺桡骨上腹胸部肋骨骨盆颅脑</inspectPosition>\n" +
                "      <inspectMethod>CT</inspectMethod>\n" +
                "      <inspectProcess />\n" +
                "      <inspectDepiction>脑实质未见明显异常密度影，双侧脑沟、脑裂、脑池大小、形态、密度未见明显异常；脑室系统未见明显异常；中线结构居中，颅骨骨质未见明显异常。\n" +
                "胸廓对称，气管纵隔居中，左侧胸腔见游离气体密度影，较前2024-08-21减少；左肺见多发斑片状磨玻璃影，边界欠清，较前减少，双肺见多发结节，部分边界较清，较前变化不明显，双肺见散在条片状高密度影；纵隔未见肿大淋巴结或肿块影，心影形态略大，冠状动脉走行区见致密影；双侧胸膜未见肥厚、粘连，双侧胸腔内见少量液体密度影。左侧肩胛骨喙突见骨折裂隙，断端对位可。\n" +
                "肋骨重建示：左侧第5、6、7肋骨见骨折裂隙，断端略错位；左侧第3、4肋骨欠规整，边缘硬化。\n" +
                "肝实质密度均匀，未见局灶性异常密度影，肝内外胆管未见扩张，脾不大，实质密度均匀；胆囊不大，壁规整，其内见类圆形高密度；胰腺大小形态及密度未见明显异常，腹膜后未见明显肿大淋巴结影。左侧肾上腺区见类圆形低密度，边界较清，直径约为20.0mm。腰背部见类圆形脂肪密度影，直径约为28.0mm。\n" +
                "骨盆诸组成骨骨质结构完整，皮质连续，双侧髋关节及骶髂关节间隙未见明显异常，未见明显骨折及脱位征象；其周围软组织未见明显肿胀。\n" +
                "左侧尺桡骨中段见裂隙，断端略错位，周围软组织肿胀。\n" +
                "</inspectDepiction>\n" +
                "      <inspectResult>左侧肩胛骨喙突骨折、左侧肋骨多发骨折复查所见左侧尺桡骨骨折并周围软组织肿胀\n" +
                "左侧肋骨陈旧性改变\n" +
                "左侧气胸、左肺挫伤、双侧少量胸腔积液复查所见\n" +
                "双肺多发小结节灶复查所见，建议年度复查\n" +
                "双肺局灶性炎症、纤维灶、心影略大、冠状动脉钙化\n" +
                "胆囊结石、腰背部皮下脂肪瘤\n" +
                "左侧肾上腺区占位，请结合临床及实验室检查，必要时结合上腹部增强CT检查\n" +
                "颅脑、骨盆CT平扫未见明显异常\n" +
                "注：因许多骨折非常细微，单次检查并不一定能准确计数，请行多次检查并对照（至少应于外伤时及外伤后3-4周做两次肋骨扫描）\n" +
                "</inspectResult>\n" +
                "      <inspectUnit>日照市岚山区人民医院</inspectUnit>\n" +
                "      <inspectDepa>CT室</inspectDepa>\n" +
                "      <rapporteur>何成顺</rapporteur>\n" +
                "      <checked>王杰</checked>\n" +
                "      <cloudBrowsingURL>http://11.227.0.14:8034/XTechReportWeb/ReportHtml/PDFPAGE.aspx?RepNo=3552741&amp;RepTypeNo=CT</cloudBrowsingURL>\n" +
                "    </MrInInspection>\n" +
                "    <MrInInspection>\n" +
                "      <medicalClass>3</medicalClass>\n" +
                "      <mdtrtsn>000347449800-1</mdtrtsn>\n" +
                "      <onlyId>000347449800-1</onlyId>\n" +
                "      <organizationId>49455020-4</organizationId>\n" +
                "      <organization>日照市岚山区人民医院</organization>\n" +
                "      <mrId>376019</mrId>\n" +
                "      <orderNo>0</orderNo>\n" +
                "      <reportNo>3552753</reportNo>\n" +
                "      <classification>04</classification>\n" +
                "      <inspectTime>2024-08-22 14:21:40</inspectTime>\n" +
                "      <inspectObjective>DR</inspectObjective>\n" +
                "      <inspectCode>002259;002297</inspectCode>\n" +
                "      <inspectName>左手正斜位(DR);左侧肘关节正侧位(DR)</inspectName>\n" +
                "      <inspectPosition>左手正斜位(DR);左侧肘关节正侧位(DR)</inspectPosition>\n" +
                "      <inspectMethod>DR</inspectMethod>\n" +
                "      <inspectProcess />\n" +
                "      <inspectDepiction>受限体位\n" +
                "左尺桡骨骨折复查：尺桡骨骨折断端错位，骨折线清，见外固定物影，余骨及关节未见明显异常征象。\n" +
                "左手组成骨骨质结构完整，骨皮质连续，未见明显骨折征象，关节间隙可。\n" +
                "</inspectDepiction>\n" +
                "      <inspectResult>左尺桡骨骨折复查表现\n" +
                "左手骨质未见明显异常\n" +
                "</inspectResult>\n" +
                "      <inspectUnit>日照市岚山区人民医院</inspectUnit>\n" +
                "      <inspectDepa>DR室</inspectDepa>\n" +
                "      <rapporteur>厉娜娜</rapporteur>\n" +
                "      <checked>郑军</checked>\n" +
                "      <cloudBrowsingURL>http://11.227.0.14:8034/XTechReportWeb/ReportHtml/PDFPAGE.aspx?RepNo=3552753&amp;RepTypeNo=DR</cloudBrowsingURL>\n" +
                "    </MrInInspection>\n" +
                "    <MrInInspection>\n" +
                "      <medicalClass>3</medicalClass>\n" +
                "      <mdtrtsn>000347449800-1</mdtrtsn>\n" +
                "      <onlyId>000347449800-1</onlyId>\n" +
                "      <organizationId>49455020-4</organizationId>\n" +
                "      <organization>日照市岚山区人民医院</organization>\n" +
                "      <mrId>376019</mrId>\n" +
                "      <orderNo>0</orderNo>\n" +
                "      <reportNo>3556240</reportNo>\n" +
                "      <classification>01</classification>\n" +
                "      <inspectTime>2024-08-26 08:58:56</inspectTime>\n" +
                "      <inspectObjective>CT</inspectObjective>\n" +
                "      <inspectCode>002391</inspectCode>\n" +
                "      <inspectName>胸部CT平扫(64排)</inspectName>\n" +
                "      <inspectPosition>胸部CT平扫（64排）</inspectPosition>\n" +
                "      <inspectMethod>CT</inspectMethod>\n" +
                "      <inspectProcess />\n" +
                "      <inspectDepiction>胸廓对称，气管纵隔居中，前次（2024-08-22）所见左侧胸腔游离气体密度影今次未见；左肺见多发斑片状磨玻璃影，边界欠清，较前减少，双肺见多发结节，部分边界较清，较前变化不明显，双肺见散在条片状高密度影；纵隔未见肿大淋巴结或肿块影，心影形态略大，冠状动脉走行区见致密影；双侧胸膜未见肥厚、粘连，双侧胸腔内见液体密度影，左侧较前增多。左侧肩胛骨喙突见骨折裂隙，断端对位可。左侧多发肋骨见骨折裂隙，断端略错位；左侧第3、4肋骨欠规整，边缘硬化。\n" +
                "</inspectDepiction>\n" +
                "      <inspectResult>左侧肩胛骨喙突骨折、左侧肋骨多发骨折复查所见\n" +
                "左侧肋骨陈旧性改变\n" +
                "左侧气胸、左肺挫伤、双侧胸腔积液复查所见\n" +
                "双肺多发小结节灶复查所见，建议年度复查\n" +
                "双肺局灶性炎症、纤维灶、心影略大、冠状动脉钙化\n" +
                "\n" +
                "\n" +
                "</inspectResult>\n" +
                "      <inspectUnit>日照市岚山区人民医院</inspectUnit>\n" +
                "      <inspectDepa>CT室</inspectDepa>\n" +
                "      <rapporteur>马良勇</rapporteur>\n" +
                "      <checked>顾洪升</checked>\n" +
                "      <cloudBrowsingURL>http://11.227.0.14:8034/XTechReportWeb/ReportHtml/PDFPAGE.aspx?RepNo=3556240&amp;RepTypeNo=CT</cloudBrowsingURL>\n" +
                "    </MrInInspection>\n" +
                "    <MrInInspection>\n" +
                "      <medicalClass>3</medicalClass>\n" +
                "      <mdtrtsn>000347449800-1</mdtrtsn>\n" +
                "      <onlyId>000347449800-1</onlyId>\n" +
                "      <organizationId>49455020-4</organizationId>\n" +
                "      <organization>日照市岚山区人民医院</organization>\n" +
                "      <mrId>376019</mrId>\n" +
                "      <orderNo>0</orderNo>\n" +
                "      <reportNo>3557335</reportNo>\n" +
                "      <classification>04</classification>\n" +
                "      <inspectObjective>DR</inspectObjective>\n" +
                "      <inspectCode>011275</inspectCode>\n" +
                "      <inspectName>医用干式激光胶片胶片11×14</inspectName>\n" +
                "      <inspectPosition />\n" +
                "      <inspectMethod>DR</inspectMethod>\n" +
                "      <inspectProcess />\n" +
                "      <inspectDepiction>胶片费\n" +
                "</inspectDepiction>\n" +
                "      <inspectResult>\n" +
                "</inspectResult>\n" +
                "      <inspectUnit>日照市岚山区人民医院</inspectUnit>\n" +
                "      <inspectDepa>DR室</inspectDepa>\n" +
                "      <rapporteur>刘向华</rapporteur>\n" +
                "      <checked>郑军</checked>\n" +
                "      <cloudBrowsingURL>http://11.227.0.14:8034/XTechReportWeb/ReportHtml/PDFPAGE.aspx?RepNo=3557335&amp;RepTypeNo=DR</cloudBrowsingURL>\n" +
                "    </MrInInspection>\n" +
                "  </mrInInspections>\n" +
                "</mrInspectionsData>";
        if(StringUtils.isNull(mrOutData)){
            return error("患者门诊基础数据为空请联系管理员");
        }
        Map<Object, Object> map = new HashMap<>();
        MrOutData mrOutDataResult = MrOutDataUtils.getMrOutData(mrOutData);

        String onlyId = mrOutDataResult.getMrOutBaisc().getOnlyId();
        mrOutDataService.deleteMrOutData(onlyId);
        new Thread(() -> {
            mrOutDataService.saveMrOutData(mrOutDataResult);
        }).start();
        map.put("mrOutData",mrOutDataResult);

        if(StringUtils.isNotNull(mrInLab)){
            List<MrInLab> mrInLabResult = MrInLabUtils.getMrInLab(mrInLab);
            mrInLabService.deleteMrInLab(onlyId);
            new Thread(() -> {
                for (MrInLab mrInLabData : mrInLabResult) {
                    mrInLabService.saveMrInLab(mrInLabData);
                }
            }).start();
            map.put("mrInLab",mrInLabResult);
        }else{
            map.put("mrInLab",null);
        }
        if(StringUtils.isNotNull(mrInspection)){
            List<MrInspection> MrInspectionResult = MrInspectionUtils.getMrInspection(mrInspection);
            mrInLabService.deleteMrInspection(onlyId);
            new Thread(() -> {
                for (MrInspection mrInspectionData : MrInspectionResult) {
                    mrInLabService.saveMrInspection(mrInspectionData);
                }
            }).start();
            map.put("mrInspection",MrInspectionResult);
        }else{
            map.put("mrInspection",null);
        }
        return success(map);
    }

    @GetMapping( "/updateMrOutData")
    public AjaxResult updateXml(MrOutBaisc mrOutBaisc) throws Exception {
        mrOutDataService.deleteMrOutBaisc(mrOutBaisc);
        mrOutDataService.saveMrOutBaisc(mrOutBaisc);

        //根据onlyId查询住院检查等信息
        MrOutData mrOutData = mrOutDataService.queryByOnlyId(mrOutBaisc.getOnlyId());
        List<MrInLab> mrInLabList = mrInLabService.queryMrInLab(mrOutBaisc.getOnlyId());
        List<MrInspection> mrInspectionList = mrInLabService.queryMrInspection(mrOutBaisc.getOnlyId());

        //将住院信息转为xml存储过程
        String mrOutDataXml = MrOutDataUtils.MrOutDataToXML(mrOutData);
        System.out.println("mrOutDataXml"+mrOutDataXml);
        String mrInLabXml = null;
        if(!mrInLabList.isEmpty()){
            mrInLabXml = MrInLabUtils.mrInLabToXML(mrInLabList);
            System.out.println(mrInLabXml);
        }
        String mrInspectionXml = null;
        if(!mrInspectionList.isEmpty()){
            mrInspectionXml = MrInspectionUtils.mrInspectionToXML(mrInspectionList);
            System.out.println(mrInspectionXml);
        }

        //将存储过程加密
        String mrOutDataSm4 = SM4Util.sm4EncryptUtil(mrOutDataXml);
        System.out.println("mrOutDataSm4" + mrOutDataSm4);

        String mrInLabSm4 = null;
        if(StringUtils.isNotNull(mrInLabXml)){
            mrInLabSm4 = SM4Util.sm4EncryptUtil(mrInLabXml);
            System.out.println("mrInLabSm4" + mrInLabSm4);
        }

        String mrInspectionSm4 = null;
        if(StringUtils.isNotNull(mrInspectionXml)){
            mrInspectionSm4 = SM4Util.sm4EncryptUtil(mrInspectionXml);
            System.out.println("mrInspectionSm4" + mrInspectionSm4);
        }



        //往接口发送数据
        String finalPatName = mrOutBaisc.getName();
        String finalMrInLabSm = mrInLabSm4;
        String finalMrInspectionSm = mrInspectionSm4;
        new Thread(() -> {
            Map json = POSTUtil.sendMrInData(mrOutDataSm4,MsgType.mrOutAcc);
            PostResult postResult = null;
            try {
                postResult = PostReturnUtils.postResult(json.get("json").toString());
            } catch (JAXBException e) {
                e.printStackTrace();
            }
            postResult.setPatName(finalPatName);
            postResult.setRucan(json.get("msg").toString());
            mrOutDataService.saveLog(postResult);
            if(StringUtils.isNotNull(finalMrInLabSm)){
                Map labJson = POSTUtil.sendMrInData(finalMrInLabSm,MsgType.mrInLabAcc);
                PostResult labResult = null;
                try {
                    labResult = PostReturnUtils.postResult(labJson.get("json").toString());
                } catch (JAXBException e) {
                    e.printStackTrace();
                }
                labResult.setPatName(finalPatName);
                labResult.setRucan(labJson.get("msg").toString());
                mrOutDataService.saveLog(labResult);
            }
            if (StringUtils.isNotNull(finalMrInspectionSm)) {
                Map inspectionJson = POSTUtil.sendMrInData(finalMrInspectionSm,MsgType.mrInspectionAcc);
                PostResult inspectionResult = null;
                try {
                    inspectionResult = PostReturnUtils.postResult(inspectionJson.get("json").toString());
                } catch (JAXBException e) {
                    e.printStackTrace();
                }
                inspectionResult.setPatName(finalPatName);
                inspectionResult.setRucan(inspectionJson.get("msg").toString());
                mrOutDataService.saveLog(inspectionResult);
            }
        }).start();
        return success("上传成功");
    }

    @GetMapping( "/updateOnlyMrOutData")
    public AjaxResult updateMrInData(MrOutBaisc mrOutBaisc) throws Exception {
        mrOutDataService.deleteMrOutBaisc(mrOutBaisc);
        mrOutDataService.saveMrOutBaisc(mrOutBaisc);

        //根据onlyId查询住院检查等信息
        MrOutData mrOutData = mrOutDataService.queryByOnlyId(mrOutBaisc.getOnlyId());

        //将住院信息转为xml存储过程
        String mrOutDataXml = MrOutDataUtils.MrOutDataToXML(mrOutData);
        System.out.println("mrOutDataXml"+mrOutDataXml);

        //将存储过程加密
        String mrOutDataSm4 = SM4Util.sm4EncryptUtil(mrOutDataXml);
        System.out.println("mrOutDataSm4" + mrOutDataSm4);
        //往接口发送数据
        Map json = POSTUtil.sendMrInData(mrOutDataSm4,MsgType.mrOutAcc);
        PostResult postResult = null;
        postResult = PostReturnUtils.postResult(json.get("json").toString());
        postResult.setPatName(mrOutBaisc.getName());
        postResult.setRucan(json.get("msg").toString());
        mrOutDataService.saveLog(postResult);
        return success(postResult.getMsgRspdesc());
    }

    @GetMapping( "/updateMrInLab")
    public AjaxResult updateMrInLab(MrOutBaisc mrOutBaisc) throws Exception {
        //根据onlyId查询住院检查等信息
        List<MrInLab> mrInLabList = mrInLabService.queryMrInLab(mrOutBaisc.getOnlyId());

        if(mrInLabList.isEmpty()){
            return success("实验室检验数据为空");
        }

        //将住院信息转为xml存储过程
        String mrInLabXml = MrInLabUtils.mrInLabToXML(mrInLabList);
        System.out.println(mrInLabXml);

        //将存储过程加密
        String mrInLabSm4 = SM4Util.sm4EncryptUtil(mrInLabXml);
        System.out.println("mrInLabSm4" + mrInLabSm4);
        //往接口发送数据
        Map json = POSTUtil.sendMrInData(mrInLabSm4,MsgType.mrInLabAcc);
        PostResult postResult = null;
        postResult = PostReturnUtils.postResult(json.get("json").toString());
        postResult.setPatName(mrOutBaisc.getName());
        postResult.setRucan(json.get("msg").toString());
        mrOutDataService.saveLog(postResult);
        return success(postResult.getMsgRspdesc());
    }

    @GetMapping( "/updateMrInspection")
    public AjaxResult updateMrInspection(MrOutBaisc mrOutBaisc) throws Exception {
        //根据onlyId查询住院检查等信息
        List<MrInspection> mrInspectionList = mrInLabService.queryMrInspection(mrOutBaisc.getOnlyId());

        if(mrInspectionList.isEmpty()){
            return success("实验室检验数据为空");
        }

        //将住院信息转为xml存储过程
        String mrInspectionXml = MrInspectionUtils.mrInspectionToXML(mrInspectionList);
        System.out.println(mrInspectionXml);

        //将存储过程加密
        String mrInspectionSm4 = SM4Util.sm4EncryptUtil(mrInspectionXml);
        System.out.println("mrInspectionSm4" + mrInspectionSm4);
        //往接口发送数据
        Map json = POSTUtil.sendMrInData(mrInspectionSm4,MsgType.mrInspectionAcc);
        PostResult postResult = null;
        postResult = PostReturnUtils.postResult(json.get("json").toString());
        postResult.setPatName(mrOutBaisc.getName());
        postResult.setRucan(json.get("msg").toString());
        mrOutDataService.saveLog(postResult);
        return success(postResult.getMsgRspdesc());
    }

}
